﻿Imports System.Data.SqlClient
Imports System.Globalization
Imports System.Text.RegularExpressions
Imports System.Reflection
Imports Excel
Imports System.Data.SqlServerCe

Namespace IHMClass
    Public Class Component
        Public tableName As String
        Private ref As String
        Private name As String
        Private version As Integer
        Private owner As String ' login d'utilisateur
        Private modifiedDate As Date ' date de modification
        Private modifyAuthor As String
        Private isOriginal As Integer
        Public dataSource As String
        Public Function getRef() As String
            Return ref
        End Function
        Public Sub setRef(ByVal _ref As String)
            ref = _ref
        End Sub
        Public Function strWrite(ByVal str As String) As String
            Dim re As String = ""
            For Each c As Char In str
                If c = "," Then
                    re = re & "."
                Else
                    re = re & c
                End If
            Next
            Return re
        End Function
        Public Function getItemByName(ByVal item As String, ByVal itemName As String) As Object
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT * From " & item & " WHERE name = '" & itemName & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()

                Dim result As New Object
                Try
                    While reader.Read()
                        result.setName(reader(0))
                        command.Dispose()
                        connection.Close()
                        Return result
                    End While
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return Nothing
        End Function
        Public dataTypeLabel() As String = {"integer number", "real number", "string", "enum"}
        Public Function isDouble(ByVal value As String) As Boolean
            Dim result As Double
            If value = "0" Then Return True
            Double.TryParse(value, result)
            If result = 0 Then
                Return False
            End If
            Return True
        End Function
        Public Function toDouble(ByVal value As String) As Double
            Dim ciClone As CultureInfo = CType(CultureInfo.InvariantCulture.Clone(), CultureInfo)
            ciClone.NumberFormat.NumberDecimalSeparator = ","
            Dim _value As Double = Double.Parse(value, ciClone)
            Return _value
        End Function
        Public Function exist(ByVal table As String, ByVal ref As String) As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT * From " & table & " WHERE ref = '" & ref & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        If reader(0) <> "" Then
                            command.Dispose()
                            connection.Close()
                            Return True
                        End If
                        command.Dispose()
                        connection.Close()
                    End While
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return False
        End Function
        Public Function getAttribute(ByVal name As String) As Object
            Try
                Return CallByName(Me, "get" & name, vbMethod)
            Catch e As Exception
                MsgBox("Name of function is invalid : " & name, vbCritical)
                Return Nothing
            End Try
        End Function
        Public Sub setAttribute(ByVal name As String, ByVal value As Object)
            Try
                CallByName(Me, "set" & name, vbMethod, value)
            Catch e As Exception
                MsgBox("Name of function is invalid : " & name & " Or Type of Value is incorrect", vbCritical)
            End Try
        End Sub
        Public Function getAllAttributeNames() As Object
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader
            Dim attributeList(0 To 50) As String
            Dim index As Integer = 0

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" & Me.tableName & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        attributeList(index) = columnNameToFunctionName(reader(0))
                        index = index + 1
                    End While
                    command.Dispose()
                    connection.Close()
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return attributeList
        End Function
        Public Function getObjectByKey(ByVal ref As String, ByVal className As String, ByVal tableName As String) As Object
            Dim obj As Object
            obj = Activator.CreateInstance(Type.GetType("WindowsApplication1.IHMClass." & className, True, True))
            obj.tableName = tableName
            If ref = "" Then
                Return obj
            End If
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader
            Dim attributeList(0 To 50) As String
            Dim index As Integer = 0
            attributeList = obj.getAllAttributeNames()

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT * FROM " & obj.tableName & " WHERE ref = '" & ref & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        While attributeList(index) <> ""
                            If IsDBNull(reader(index)) Then
                                If attributeList(index) = "ModifiedDate" Then
                                    obj.setAttribute(columnNameToFunctionName(attributeList(index)), Today)
                                Else
                                    obj.setAttribute(columnNameToFunctionName(attributeList(index)), Nothing)
                                End If
                            Else
                                obj.setAttribute(columnNameToFunctionName(attributeList(index)), reader(index).ToString)
                            End If
                            index = index + 1
                        End While
                    End While
                    command.Dispose()
                    connection.Close()
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return obj
        End Function
        Public Function columnNameToFunctionName(ByVal name As String) As String
            Dim _name As String = ""
            Dim mark As Boolean = True
            For Each c As Char In name
                If c = "_" Then
                    mark = True
                ElseIf mark = True Then
                    _name = _name & c.ToString.ToUpper
                    mark = False
                Else
                    _name = _name & c
                End If
            Next
            Return _name
        End Function
        Public Function update(ByVal fieldName As String) As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "UPDATE " & tableName & " SET " & fieldName & " = '" & strWrite(getAttribute(columnNameToFunctionName(fieldName))) & "' WHERE ref = '" & ref & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return False
        End Function
        Public Function insert() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "INSERT INTO " & tableName & " (ref) VALUES ('" & ref & "')"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return False
        End Function
        Public Sub setVersion(ByVal _version As Integer)
            version = _version
        End Sub
        Public Sub setOwner(ByVal _editor As String)
            owner = _editor
        End Sub
        Public Sub setModifiedDate(ByVal _date As Date)
            modifiedDate = _date
        End Sub
        Public Function getVersion() As Integer
            Return version
        End Function
        Public Function getOwner() As String
            Return owner
        End Function
        Public Function getModifiedDate() As Date
            Return modifiedDate
        End Function
        Public Sub setIsOriginal(ByVal v As Integer)
            isOriginal = v
        End Sub
        Public Function getIsOriginal() As Integer
            Return isOriginal
        End Function
        Public Function updateAll() As Boolean
            Dim obj As Object
            obj = Activator.CreateInstance(Type.GetType("WindowsApplication1.IHMClass." & columnNameToFunctionName(tableName), True, True))
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim attributeList(0 To 50) As String
            attributeList = obj.getAllAttributeNames()
            Dim index As Integer = 1

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "UPDATE " & tableName
            Dim isFirstClause = True
            While attributeList(index) <> ""
                While getAttribute(attributeList(index)) Is Nothing
                    index += 1
                    If attributeList(index) = "" Then
                        Exit While
                    End If
                End While
                If attributeList(index) = "" Then
                    Exit While
                End If
                If isFirstClause Then
                    sql = sql & " SET " & functionNameToColumnName(attributeList(index)) & " = '" & strWrite(getAttribute(attributeList(index))) & "'"
                    isFirstClause = False
                Else
                    If attributeList(index) = "ModifiedDate" Then
                        sql = sql & ", " & functionNameToColumnName(attributeList(index)) & " = CONVERT(datetime, '" & strWrite(getAttribute(attributeList(index))) & "', 103)"
                    Else
                        sql = sql & ", " & functionNameToColumnName(attributeList(index)) & " = '" & strWrite(getAttribute(attributeList(index))) & "'"
                    End If
                End If
                index += 1
            End While
            sql = sql + " WHERE ref = '" & getRef() & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
                Return True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return False
        End Function
        Public Function functionNameToColumnName(ByVal name As String) As String
            Dim _name As String = ""
            For Each e As Char In name
                If Not Char.IsLower(e) And Not IsNumeric(e) Then
                    _name = _name & "_" & e.ToString.ToLower()
                Else
                    _name = _name & e
                End If
            Next
            _name = _name.Substring(1)
            Return _name
        End Function

        Function delete() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "DELETE FROM " & tableName & " WHERE ref = '" & ref & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
                Return True
            Catch ex As Exception
                MsgBox("Component is in used, it cant be deleted", vbCritical)
            End Try
            Return False
        End Function
        Public Function getFieldInfo(ByVal fieldName As String, ByVal field_info As String) As Object
            Dim info As New Object
            info = Nothing
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT " & field_info & " From field_info WHERE table_name = '" & tableName & "' AND field_name = '" & fieldName & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()

                Try
                    While reader.Read()
                        info = reader(0)
                        command.Dispose()
                        connection.Close()
                        If field_info = "data_type" And Not IsDBNull(info) Then
                            Return dataTypeLabel(info)
                        ElseIf Not IsDBNull(info) Then
                            Return info
                        Else : Return Nothing
                        End If

                    End While
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try

            If field_info = "data_type" And Not IsDBNull(info) Then
                Return dataTypeLabel(info)
            ElseIf Not IsDBNull(info) Then
                Return info
            Else : Return Nothing
            End If
        End Function

        Public Sub setName(ByVal value As String)
            name = value
        End Sub

        Public Function getName() As String
            Return name
        End Function

        Public Sub setModifyAuthor(ByVal value As String)
            modifyAuthor = value
        End Sub

        Public Function getModifyAuthor() As String
            Return modifyAuthor
        End Function

    End Class
    Public Class Alternator
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private voltage As Double
        Private nominalOutput As Double
        Private electricalDefinition As String
        Private polePairsNumber As Integer
        Private rotor As String
        Private stator As String
        Private rectifier As String
        Private regulator As String
        Private brush As String
        Private statorAssembly As String
        Public childrenList() As String = {"stator_assembly", "rotor"}
        Sub New()
            tableName = "alternator"
        End Sub
        Public Function getVoltage() As Double
            Return voltage
        End Function
        Public Function getNominalOutput() As Double
            Return nominalOutput
        End Function
        Public Function getElectricalDefinition() As String
            Return electricalDefinition
        End Function
        Public Function getPolePairsNumber() As Integer
            Return polePairsNumber
        End Function
        Public Function getStator() As String
            Return stator
        End Function
        Public Function getRotor() As String
            Return rotor
        End Function
        Public Function getRectifier() As String
            Return rectifier
        End Function
        Public Function getRegulator() As String
            Return regulator
        End Function
        Public Function getBrush() As String
            Return brush
        End Function
        Public Function getStatorAssembly() As String
            Return statorAssembly
        End Function
        Public Sub setVoltage(ByVal v As Double)
            voltage = v
        End Sub
        Public Sub setNominalOutput(ByVal Inom As Double)
            nominalOutput = Inom
        End Sub
        Public Sub setElectricalDefinition(ByVal eD As String)
            electricalDefinition = eD
        End Sub
        Public Sub setPolePairsNumber(ByVal number As Integer)
            polePairsNumber = number
        End Sub
        Public Sub setRotor(ByVal rotorName As String)
            rotor = rotorName
        End Sub
        Public Sub setStator(ByVal statorName As String)
            stator = statorName
        End Sub
        Public Sub setRectifier(ByVal recName As String)
            rectifier = recName
        End Sub
        Public Sub setBrush(ByVal brushName As String)
            brush = brushName
        End Sub
        Public Sub setRegulator(ByVal regName As String)
            regulator = regName
        End Sub
        Public Sub setStatorAssembly(ByVal name As String)
            statorAssembly = name
        End Sub

        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class Stator
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private statorCore As String
        Private statorCoil As String
        Private slotDefinition As String
        Private thermalCoefficient As String
        Public childrenList() As String = {"stator_core", "stator_coil", "slot_definition", "thermal_coefficient"}

        Sub New()
            ' TODO: Complete member initialization 
            tableName = "stator"
        End Sub
        Public Sub setStatorCore(ByVal _statorCore As String)
            statorCore = _statorCore
        End Sub
        Public Sub setStatorCoil(ByVal _statorCoil As String)
            statorCoil = _statorCoil
        End Sub
        Public Sub setSlotDefinition(ByVal _slotDef As String)
            slotDefinition = _slotDef
        End Sub
        Public Sub setThermalCoefficient(ByVal thermalCoeff As String)
            thermalCoefficient = thermalCoeff
        End Sub
        Public Function getStatorCore() As String
            Return statorCore
        End Function
        Public Function getStatorCoil() As String
            Return statorCoil
        End Function
        Public Function getSlotDefinition() As String
            Return slotDefinition
        End Function
        Public Function getThermalCoefficient() As String
            Return thermalCoefficient
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class Rotor
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private mountingType As String
        Private thermalTreatment As Integer
        Private outerDiameter As Double
        Private coreLength As Double
        Private centeringLengthOfClawPole As Double
        Private centeringDiameterOfClawPole As Double
        Private shaftDiameter As Double
        Private materialMagnetic As String
        Private clawPoles As String
        Private brushCollection As String
        Private fan As String
        Private fieldCore As String
        Private fieldCoil As String
        Private thermalCoefficient As String
        Public childrenList() As String = {"claw_poles", "field_coil", "thermal_coefficient", "material_magnetic"}

        Sub New()
            ' TODO: Complete member initialization 
            tableName = "rotor"
        End Sub
        Public Sub setMountingType(ByVal mt As String)
            mountingType = mt
        End Sub
        Public Sub setClawPoles(ByVal _clawPoles As String)
            clawPoles = _clawPoles
        End Sub
        Public Sub setBrushCollector(ByVal bC As String)
            brushCollection = bC
        End Sub
        Public Sub setFan(ByVal _fan As String)
            fan = _fan
        End Sub
        Public Sub setFieldCore(ByVal _fieldCore As String)
            fieldCore = _fieldCore
        End Sub
        Public Sub setFieldCoil(ByVal _fieldCoil As String)
            fieldCoil = _fieldCoil
        End Sub
        Public Sub setThermalCoefficient(ByVal _thermalCoefficient As String)
            thermalCoefficient = _thermalCoefficient
        End Sub
        Public Sub setOuterDiameter(ByVal value As Double)
            outerDiameter = value
        End Sub
        Public Sub setCoreLength(ByVal value As Double)
            coreLength = value
        End Sub
        Public Sub setCenteringLengthOfClawPole(ByVal value As Double)
            centeringLengthOfClawPole = value
        End Sub
        Public Sub setCenteringDiameterOfClawPole(ByVal value As Double)
            centeringDiameterOfClawPole = value
        End Sub
        Public Sub setShaftDiameter(ByVal value As Double)
            shaftDiameter = value
        End Sub
        Public Sub setThermalTreatment(ByVal value As Integer)
            thermalTreatment = value
        End Sub
        Public Sub setMaterialMagnetic(ByVal value As String)
            materialMagnetic = value
        End Sub
        Public Function getOuterDiameter() As Double
            Return outerDiameter
        End Function
        Public Function getCoreLength() As Double
            Return coreLength
        End Function
        Public Function getCenteringLengthOfClawPole() As Double
            Return centeringLengthOfClawPole
        End Function
        Public Function getCenteringDiameterOfClawPole() As Double
            Return centeringDiameterOfClawPole
        End Function
        Public Function getShaftDiameter() As Double
            Return shaftDiameter
        End Function
        Public Function getThermalTreatment() As Integer
            Return thermalTreatment
        End Function
        Public Function getMaterialMagnetic() As String
            Return materialMagnetic
        End Function
        Public Function getMountingType() As String
            Return mountingType
        End Function
        Public Function getClawPoles() As String
            Return clawPoles
        End Function
        Public Function getBrushCollector() As String
            Return brushCollection
        End Function
        Public Function getFan() As String
            Return fan
        End Function
        Public Function getFieldCore() As String
            Return fieldCore
        End Function
        Public Function getFieldCoil() As String
            Return fieldCoil
        End Function
        Public Function getThermalCoefficient() As String
            Return thermalCoefficient
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
        Public Function getMagnetList() As Object
            Dim magnetList(0 To 50) As String
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader

            Dim index As Integer = 0
            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT magnet FROM rotor_magnet WHERE rotor = '" & getRef() & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        magnetList(index) = reader(0)
                        index = index + 1
                    End While
                    command.Dispose()
                    connection.Close()
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            Return magnetList
        End Function
        Public Function getRotorMagnet(ByVal magnet As String) As RotorMagnet
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader
            Dim rotorMagnet As New RotorMagnet(getRef(), magnet)
            Dim exist As Boolean = False

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT quantity FROM rotor_magnet WHERE rotor = '" & getRef() & "' AND  magnet = '" & magnet & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        rotorMagnet.setQuantity(reader(0).ToString)
                        exist = True
                    End While
                    command.Dispose()
                    connection.Close()
                Finally
                    reader.Close()
                End Try

            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            If exist Then
                Return rotorMagnet
            Else
                Return Nothing
            End If
        End Function
    End Class
    Public Class Rectifier
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private diodeNominalCurrent As Double
        Private numberOfParallelDiodes As Double
        Private requirement As Double
        Private neutralPointRectifying As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "rectifier"
        End Sub
        Public Sub setDiodeNominalCurrent(ByVal diodeNominalCurrent As Double)
            Me.diodeNominalCurrent = diodeNominalCurrent
        End Sub
        Public Sub setNumberOfParallelDiodes(ByVal numberOfParallelDiodes As Double)
            Me.numberOfParallelDiodes = numberOfParallelDiodes
        End Sub
        Public Sub setRequirement(ByVal requirement As Double)
            Me.requirement = requirement
        End Sub
        Public Sub setNeutralPointRectifying(ByVal neutralPointRectifying As Double)
            Me.neutralPointRectifying = neutralPointRectifying
        End Sub
        Public Function getDiodeNominalCurrent() As Double
            Return Me.diodeNominalCurrent
        End Function
        Public Function getNumberOfParallelDiodes() As Double
            Return diodeNominalCurrent
        End Function
        Public Function getRequirement() As Double
            Return Me.requirement
        End Function
        Public Function getNeuTralPointRectifying() As Double
            Return Me.neutralPointRectifying
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class Regulator
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private voltageDropFor4A As Double
        Public childrenList() As String = {}
        Sub New()
            ' TODO: Complete member initialization 
            tableName = "regulator"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
        Public Sub setVoltageDropFor4A(ByVal voltageDropFor4A As Double)
            Me.voltageDropFor4A = voltageDropFor4A
        End Sub
        Public Function getVoltageDropFor4A() As Double
            Return Me.voltageDropFor4A
        End Function
    End Class
    Public Class Brush
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private voltageDropFor4A As Double
        Private voltageDropWithShuntFor4A As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "brush"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
        Public Sub setVoltageDropFor4A(ByVal voltageDropFor4A As Double)
            Me.voltageDropFor4A = voltageDropFor4A
        End Sub
        Public Sub setVoltageDropWithShuntFor4A(ByVal voltageDropWithShuntFor4A As Double)
            Me.voltageDropWithShuntFor4A = voltageDropWithShuntFor4A
        End Sub
        Public Function getVoltageDropFor4A() As Double
            Return Me.voltageDropFor4A
        End Function
        Public Function getVoltageDropWithShuntFor4A() As Double
            Return Me.voltageDropWithShuntFor4A
        End Function
    End Class
    Public Class StatorCore
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private materialMagnetic As String
        Private outerDiameter As Double
        Private stackLength As Double
        Private laminationSheetThickness As Double
        Private innerDiameter As Double
        Public childrenList() As String = {"material_magnetic"}
        Sub New()
            tableName = "stator_core"
        End Sub
        Public Sub setMaterialMagnetic(ByVal _material)
            materialMagnetic = _material
        End Sub
        Public Sub setOuterDiameter(ByVal _outerDiameter As Double)
            outerDiameter = _outerDiameter
        End Sub
        Public Sub setStackLength(ByVal _stackLength As Double)
            stackLength = _stackLength
        End Sub
        Public Sub setLaminationSheetThickness(ByVal _laminationSheetThickness As Double)
            laminationSheetThickness = _laminationSheetThickness
        End Sub
        Public Sub setInnerDiameter(ByVal _innerDiameter As Double)
            innerDiameter = _innerDiameter
        End Sub
        Public Function getMaterialMagnetic() As String
            Return materialMagnetic
        End Function
        Public Function getOuterDiameter() As Double
            Return outerDiameter
        End Function
        Public Function getStackLength() As Double
            Return stackLength
        End Function
        Public Function getLaminationSheetThickness() As Double
            Return laminationSheetThickness
        End Function
        Public Function getInnerDiameter() As Double
            Return innerDiameter
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class SlotDefinition
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private slotNumber As Integer
        Private teethWidth As Double
        Private slotHeight As Double
        Private slotOpening As Double
        Private bottomSlotCornerRadius As Double
        Private teethShoeHeight As Double
        Private slotOpeningHeight As Double
        Private slotWithParalleSides As Integer
        Private slotWidth As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "slot_definition"
        End Sub
        Public Sub setSlotNumber(ByVal _slotNumber As Double)
            slotNumber = _slotNumber
        End Sub
        Public Sub setTeethWidth(ByVal _teethWidth As Double)
            teethWidth = _teethWidth
        End Sub
        Public Sub setSlotHeight(ByVal _slotHeight As Double)
            slotHeight = _slotHeight
        End Sub
        Public Sub setSlotOpening(ByVal _slotOpening As Double)
            slotOpening = _slotOpening
        End Sub
        Public Sub setBottomSlotCornerRadius(ByVal bSlotCornerRadius As String)
            bottomSlotCornerRadius = bSlotCornerRadius
        End Sub
        Public Sub setTeethShoeHeight(ByVal _teethShoeHeight As Double)
            teethShoeHeight = _teethShoeHeight
        End Sub
        Public Sub setSlotOpeningHeight(ByVal _slotOpeningHeight As Double)
            slotOpeningHeight = _slotOpeningHeight
        End Sub
        Public Sub setSlotWithParallelSides(ByVal value As Integer)
            slotWithParalleSides = value
        End Sub
        Public Sub setSlotWidth(ByVal slotWidth As Double)
            Me.slotWidth = slotWidth
        End Sub
        Public Function getSlotWithParallelSides() As Integer
            Return slotWithParalleSides
        End Function
        Public Function getSlotWidth() As Double
            Return slotWidth
        End Function
        Public Function getSlotNumber() As Integer
            Return slotNumber
        End Function
        Public Function getTeethWidth() As Double
            Return teethWidth
        End Function
        Public Function getSlotHeight() As Double
            Return slotHeight
        End Function
        Public Function getSlotOpening() As Double
            Return slotOpening
        End Function
        Public Function getBottomSlotCornerRadius() As Double
            Return bottomSlotCornerRadius
        End Function
        Public Function getTeethShoeHeight() As Double
            Return teethShoeHeight
        End Function
        Public Function getSlotOpeningHeight() As Double
            Return slotOpeningHeight
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class StatorCoil
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private materialConductor As String
        Private phaseNumber As Integer
        Private turnsNumberPerPhase As Integer
        Private parallelWiresNumber As Integer
        Private wireDiameter As Double
        Private connectionType As Integer
        Private windingType As Integer
        Private thermalGrade As Double 'can be 0
        Private slotWedgeThickness As Double
        Private endWindingHeight As Double
        Private coilLength As Double
        Private phaseToPhaseResistanceAt20 As Double
        Private phaseResistanceAt20 As Double
        Private nonInsulatedSlotArea As Double
        Private copperArea As Double
        Private fillFactor As Double
        Private copperWeight As Double
        Private wireType As Integer
        Private wireWidth As Double
        Private wireHeight As Double
        Public childrenList() As String = {"material_conductor"}
        Sub New()
            tableName = "stator_coil"
        End Sub
        Public Sub setMaterialConductor(ByVal _material As String)
            materialConductor = _material
        End Sub

        Public Sub setPhaseNumber(ByVal _phaseNumber As Integer)
            phaseNumber = _phaseNumber
        End Sub
        Public Sub setTurnsNumberPerPhase(ByVal _turnsNumberPerPhase As Integer)
            turnsNumberPerPhase = _turnsNumberPerPhase
        End Sub
        Public Sub setParallelWiresNumber(ByVal _parallelWiresNumber As Integer)
            parallelWiresNumber = _parallelWiresNumber
        End Sub
        Public Sub setWireDiameter(ByVal _wireDiameter As Double)
            wireDiameter = _wireDiameter
        End Sub
        Public Sub setconnectionType(ByVal _connectionType As Integer)
            connectionType = _connectionType
        End Sub
        Public Sub setWindingType(ByVal _windingType As Integer)
            windingType = _windingType
        End Sub
        Public Sub setThermalGrade(ByVal _thermalGrade As Double)
            thermalGrade = _thermalGrade
        End Sub
        Public Sub setSlotWedgeThickness(ByVal _slotWedgeThickness As Double)
            slotWedgeThickness = _slotWedgeThickness
        End Sub
        Public Sub setEndWindingHeight(ByVal _endWindingHeight As Double)
            endWindingHeight = _endWindingHeight
        End Sub
        Public Sub setCoilLength(ByVal _coilLength As Double)
            coilLength = _coilLength
        End Sub
        Public Sub setPhaseToPhaseResistanceAt20(ByVal _phaseToPhaseResistanceAt20 As Double)
            phaseToPhaseResistanceAt20 = _phaseToPhaseResistanceAt20
        End Sub
        Public Sub setPhaseResistanceAt20(ByVal _phaseResistanceAt20 As Double)
            phaseResistanceAt20 = _phaseResistanceAt20
        End Sub
        Public Sub setNonInsulatedSlotArea(ByVal _nonInsulatedSlotArea As Double)
            nonInsulatedSlotArea = _nonInsulatedSlotArea
        End Sub
        Public Sub setCopperArea(ByVal _copperArea As Double)
            copperArea = _copperArea
        End Sub
        Public Sub setFillFactor(ByVal _fillFactor As Double)
            fillFactor = _fillFactor
        End Sub
        Public Sub setcopperWeight(ByVal _copperWeight As Double)
            copperWeight = _copperWeight
        End Sub
        Public Sub setWireType(ByVal wireType As Integer)
            Me.wireType = wireType
        End Sub
        Public Sub setWireWidth(ByVal wireWidth As Double)
            Me.wireWidth = wireWidth
        End Sub
        Public Sub setWireHeight(ByVal wireHeight As Double)
            Me.wireHeight = wireHeight
        End Sub
        Public Function getWireType() As Integer
            Return wireType
        End Function
        Public Function getWireWidth() As Double
            Return wireWidth
        End Function
        Public Function getWireHeight() As Double
            Return wireHeight
        End Function
        Public Function getMaterialConductor() As String
            Return materialConductor
        End Function

        Public Function getPhaseNumber() As Integer
            Return phaseNumber
        End Function
        Public Function getTurnsNumberPerPhase() As Integer
            Return turnsNumberPerPhase
        End Function
        Public Function getParallelWiresNumber() As Integer
            Return parallelWiresNumber
        End Function
        Public Function getWireDiameter() As Integer
            Return wireDiameter
        End Function
        Public Function getConnectionType() As Integer
            Return connectionType
        End Function
        Public Function getWindingType() As Integer
            Return windingType
        End Function
        Public Function getThermalGrade() As Double
            Return thermalGrade
        End Function
        Public Function getSlotWedgeThickness() As Double
            Return slotWedgeThickness
        End Function
        Public Function getEndWindingHeight() As Double
            Return endWindingHeight
        End Function
        Public Function getCoilLength() As Double
            Return coilLength
        End Function
        Public Function getPhaseToPhaseResistanceAt20() As Double
            Return phaseToPhaseResistanceAt20
        End Function
        Public Function getPhaseResistanceAt20() As Double
            Return phaseResistanceAt20
        End Function
        Public Function getNonInsulatedSlotArea() As Double
            Return nonInsulatedSlotArea
        End Function
        Public Function getCopperArea() As Double
            Return copperArea
        End Function
        Public Function getFillFactor() As Double
            Return fillFactor
        End Function
        Public Function getCopperWeight() As Double
            Return copperWeight
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class ThermalCoefficient
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private ref As String
        Private a_th As Double
        Private alpha As Double
        Private k_th As Double
        Private Tamb_ref As Double
        Private G_nat As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "thermal_coefficient"
        End Sub
        Public Function getATh() As Double
            Return a_th
        End Function
        Public Function getAlpha() As Double
            Return alpha
        End Function
        Public Function getKTh() As Double
            Return k_th
        End Function
        Public Function getTambRef() As Double
            Return Tamb_ref
        End Function
        Public Function getGNat() As Double
            Return G_nat
        End Function
        Public Sub setATh(ByVal _a_th As Double)
            a_th = _a_th
        End Sub
        Public Sub setAlpha(ByVal _alpha As Double)
            alpha = _alpha
        End Sub
        Public Sub setKTh(ByVal _k_th As Double)
            k_th = _k_th
        End Sub
        Public Sub setTambRef(ByVal _Tamb_ref As Double)
            Tamb_ref = _Tamb_ref
        End Sub
        Public Sub setGnat(ByVal _G_nat As Double)
            G_nat = _G_nat
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class ClawPoles
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private materialMagnetic As String
        Private thermalTreatment As String
        Private outerDiameter As Double
        Private poleEndDiscThickness As Double
        Private innerRadiusAtClawBandPart As Double
        Private clawLengthAtSlopeChange As Double
        Private innerDiameterAtSlopeChange As Double
        Private innerRadiusAtSlopeChange As Double
        Private totalClawLength As Double
        Private totalClawEnd As Double
        Private innerDiameterAtTip As Double
        Private contactThickness As Double
        Private poleEndDiscDiameter As Double
        Private clawLengthAtACut As Double
        Private clawWidthAtACut As Double
        Private machinedHalfWidthAtACut As Double
        Private machinedHalfWidthAtBCut As Double
        Private clawLengthAtBCut As Double
        Private clawWidthAtBCut As Double
        Private clawWidthAtRoot As Double
        Private maxiClawLength As Double
        Private clawLateralAngle As Double
        Private chamferType As String
        Private chamferAngle As Double
        Public childrenList() As String = {"material_magnetic"}
        Sub New()
            tableName = "claw_poles"
        End Sub
        Public Sub setMaterialMagnetic(ByVal _material As String)
            materialMagnetic = _material
        End Sub
        Public Sub setThermalTreatment(ByVal _thermalTreatment As String)
            thermalTreatment = _thermalTreatment
        End Sub
        Public Sub setOuterDiameter(ByVal _outerDiameter As Double)
            outerDiameter = _outerDiameter
        End Sub
        Public Sub setPoleEndDiscThickness(ByVal _poleEndDiscThickness As Double)
            poleEndDiscThickness = _poleEndDiscThickness
        End Sub
        Public Sub setInnerRadiusAtClawBandPart(ByVal _innerRadiusAtClawBandPart As Double)
            innerRadiusAtClawBandPart = _innerRadiusAtClawBandPart
        End Sub
        Public Sub setInnerRadiusAtSlopeChange(ByVal _innerRadiusAtSlopeChange As Double)
            innerRadiusAtSlopeChange = _innerRadiusAtSlopeChange
        End Sub
        Public Sub setClawLengthAtSlopeChange(ByVal _clawLengthAtSlopeChange As Double)
            clawLengthAtSlopeChange = _clawLengthAtSlopeChange
        End Sub
        Public Sub setInnerDiameterAtSlopeChange(ByVal _innerDiameterAtSlopeChange As Double)
            innerDiameterAtSlopeChange = _innerDiameterAtSlopeChange
        End Sub
        Public Sub setTotalClawLength(ByVal _totalClawLength As Double)
            totalClawLength = _totalClawLength
        End Sub
        Public Sub setTotalClawEnd(ByVal _totalClawEnd As Double)
            totalClawEnd = _totalClawEnd
        End Sub
        Public Sub setInnerDiameterAtTip(ByVal _innerDiameterAtTip As Double)
            innerDiameterAtTip = _innerDiameterAtTip
        End Sub
        Public Sub setContactThickness(ByVal _contactThickness As Double)
            contactThickness = _contactThickness
        End Sub
        Public Sub setPoleEndDiscDiameter(ByVal _poleEndDiscDiameter As Double)
            poleEndDiscDiameter = _poleEndDiscDiameter
        End Sub
        Public Sub setClawLengthAtACut(ByVal _clawLengthAtACut As Double)
            clawLengthAtACut = _clawLengthAtACut
        End Sub
        Public Sub setClawWidthAtACut(ByVal _clawWidthAtACut As Double)
            clawWidthAtACut = _clawWidthAtACut
        End Sub
        Public Sub setMachinedHalfWidthAtACut(ByVal _machinedHalfWidthAtACut As Double)
            machinedHalfWidthAtACut = _machinedHalfWidthAtACut
        End Sub
        Public Sub setMachinedHalfWidthAtBCut(ByVal _machinedHalfWidthAtBCut As Double)
            machinedHalfWidthAtBCut = _machinedHalfWidthAtBCut
        End Sub
        Public Sub setClawLengthAtBCut(ByVal _clawLengthAtBCut As Double)
            clawLengthAtBCut = _clawLengthAtBCut
        End Sub
        Public Sub setClawWidthAtBCut(ByVal _clawWidthAtBCut As Double)
            clawWidthAtBCut = _clawWidthAtBCut
        End Sub
        Public Sub setClawWidthAtRoot(ByVal _clawWidthAtRoot As Double)
            clawWidthAtRoot = _clawWidthAtRoot
        End Sub
        Public Sub setMaxiClawLength(ByVal _maxiClawLength As Double)
            maxiClawLength = _maxiClawLength
        End Sub
        Public Sub setClawLateralAngle(ByVal _clawLateralAngle As Double)
            clawLateralAngle = _clawLateralAngle
        End Sub
        Public Sub setChamferType(ByVal _chamferType As String)
            chamferType = _chamferType
        End Sub
        Public Sub setChamferAngle(ByVal _chamferAngle As Double)
            chamferAngle = _chamferAngle
        End Sub
        Public Function getMaterialMagnetic() As String
            Return materialMagnetic
        End Function
        Public Function getThermalTreatment() As String
            Return thermalTreatment
        End Function
        Public Function getOuterDiameter() As Double
            Return outerDiameter
        End Function
        Public Function getPoleEndDiscThickness() As Double
            Return poleEndDiscThickness
        End Function
        Public Function getInnerRadiusAtClawBandPart() As Double
            Return innerRadiusAtClawBandPart
        End Function
        Public Function getInnerRadiusAtSlopeChange() As Double
            Return innerRadiusAtSlopeChange
        End Function
        Public Function getClawLengthAtSlopeChange() As Double
            Return clawLengthAtSlopeChange
        End Function
        Public Function getInnerDiameterAtSlopeChange() As Double
            Return innerDiameterAtSlopeChange
        End Function
        Public Function getTotalClawLength() As Double
            Return totalClawLength
        End Function
        Public Function getTotalClawEnd() As Double
            Return totalClawEnd
        End Function
        Public Function getInnerDiameterAtTip() As Double
            Return innerDiameterAtTip
        End Function
        Public Function getContactThickness() As Double
            Return contactThickness
        End Function
        Public Function getPoleEndDiscDiameter() As Double
            Return poleEndDiscDiameter
        End Function
        Public Function getClawLengthAtACut() As Double
            Return clawLengthAtACut
        End Function
        Public Function getClawWidthAtACut() As Double
            Return clawWidthAtACut
        End Function
        Public Function getMachinedHalfWidthAtACut() As Double
            Return machinedHalfWidthAtACut
        End Function
        Public Function getMachinedHalfWidthAtBCut() As Double
            Return machinedHalfWidthAtBCut
        End Function
        Public Function getClawLengthAtBCut() As Double
            Return clawLengthAtBCut
        End Function
        Public Function getClawWidthAtBcut() As Double
            Return clawWidthAtBCut
        End Function
        Public Function getClawWidthAtRoot() As Double
            Return clawWidthAtRoot
        End Function
        Public Function getMaxiClawLength() As Double
            Return maxiClawLength
        End Function
        Public Function getClawLateralAngle() As Double
            Return clawLateralAngle
        End Function
        Public Function getChamferType() As String
            Return chamferType
        End Function
        Public Function getChamferAngle() As Double
            Return chamferAngle
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class BrushCollector
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {}
        Sub New()
            tableName = "brush_collector"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class Fan
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {}
        Sub New()
            tableName = "fan"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class FieldCore
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private materialMagnetic As String
        Private thermalTreatment As String
        Private outerDiameter As Double
        Private coreLength As Double
        Private centeringLengthOfClawPole As Double
        Private centeringDiameterOfClawPole As Double
        Private shaftDiameter As Double
        Public childrenList() As String = {"material_magnetic"}
        Sub New()
            tableName = "field_core"
        End Sub
        Public Sub setMaterialMagnetic(ByVal _material As String)
            materialMagnetic = _material
        End Sub
        Public Sub setThermalTreatment(ByVal _thermalTreatment As String)
            thermalTreatment = _thermalTreatment
        End Sub
        Public Sub setOuterDiameter(ByVal _outerDiameter As Double)
            outerDiameter = _outerDiameter
        End Sub
        Public Sub setCoreLength(ByVal _coreLength As Double)
            coreLength = _coreLength
        End Sub
        Public Sub setCenteringLengthOfClawPole(ByVal _centeringLengthOfClowPole As Double)
            centeringLengthOfClawPole = _centeringLengthOfClowPole
        End Sub
        Public Sub setCenteringDiameterOfClawPole(ByVal _centeringDiameterOfclawPole As Double)
            centeringDiameterOfClawPole = _centeringDiameterOfclawPole
        End Sub
        Public Sub setShaftDiameter(ByVal _shaftDiameter As Double)
            shaftDiameter = _shaftDiameter
        End Sub
        Public Function getMaterialMagnetic() As String
            Return materialMagnetic
        End Function
        Public Function getThermalTreatment() As String
            Return thermalTreatment
        End Function
        Public Function getOuterDiameter() As Double
            Return outerDiameter
        End Function
        Public Function getCoreLength() As Double
            Return coreLength
        End Function
        Public Function getCenteringLengthOfClawPole() As Double
            Return centeringLengthOfClawPole
        End Function
        Public Function getCenteringDiameterOfClawPole() As Double
            Return centeringDiameterOfClawPole
        End Function
        Public Function getShaftDiameter() As Double
            Return shaftDiameter
        End Function
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class FieldCoil
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {"material_conductor"}
        Private materialConductor As String
        Private turnsNumber As Integer
        Private wireDiameter As Double
        Private resistanceAt20 As Double
        Private filGrad1IndiceDeTemps As Double
        Private layersNumber As Double
        Private turnsPerLayer As Double
        Private maximalLayerNumber As Double
        Private maxiCopperArea As Double
        Private actualCopperArea As Double
        Private feasability As String
        Private maxiTurnsNumber As Double
        Private copperWeight As Double


        Sub New()
            ' TODO: Complete member initialization 
            tableName = "field_coil"
        End Sub
        Public Function getMaterialConductor() As String
            Return materialConductor
        End Function
        Public Function getTurnsNumber() As Integer
            Return turnsNumber
        End Function
        Public Function getWireDiameter() As Double
            Return wireDiameter
        End Function
        Public Function getResistanceAt20() As Double
            Return resistanceAt20
        End Function
        Public Function getFilGrad1IndiceDeTemps() As Double
            Return filGrad1IndiceDeTemps
        End Function
        Public Function getLayersNumber() As Double
            Return layersNumber
        End Function
        Public Function getTurnsPerLayer() As Double
            Return turnsPerLayer
        End Function
        Public Function getMaximalLayerNumber() As Double
            Return maximalLayerNumber
        End Function
        Public Function getMaxiCopperArea() As Double
            Return maxiCopperArea
        End Function
        Public Function getActualCopperArea() As Double
            Return actualCopperArea
        End Function
        Public Function getFeasability() As String
            Return feasability
        End Function
        Public Function getMaxiTurnsNumber() As Double
            Return maxiTurnsNumber
        End Function
        Public Function getCopperWeight() As Double
            Return copperWeight
        End Function
        Public Sub setMaterialConductor(ByVal _material As String)
            materialConductor = _material
        End Sub
        Public Sub setTurnsNumber(ByVal _turnsNumber As Integer)
            turnsNumber = _turnsNumber
        End Sub
        Public Sub setWireDiameter(ByVal _wireDiameter As Double)
            wireDiameter = _wireDiameter
        End Sub
        Public Sub setResistanceAt20(ByVal _resistanceAt20 As Double)
            resistanceAt20 = _resistanceAt20
        End Sub
        Public Sub setFilGrad1IndiceDeTemps(ByVal _filGrand1IndiceDeTemps As Double)
            filGrad1IndiceDeTemps = _filGrand1IndiceDeTemps
        End Sub
        Public Sub setLayersNumber(ByVal _layernumber As Double)
            layersNumber = _layernumber
        End Sub
        Public Sub setTurnsPerLayer(ByVal _turnsPerLayer As Double)
            turnsPerLayer = _turnsPerLayer
        End Sub
        Public Sub setMaximalLayerNumber(ByVal _maximalLayerNumber As Double)
            maximalLayerNumber = _maximalLayerNumber
        End Sub
        Public Sub setMaxiCopperArea(ByVal _maxiCopperArea As Double)
            maxiCopperArea = _maxiCopperArea
        End Sub
        Public Sub setActualCopperArea(ByVal _actualCopperArea As Double)
            actualCopperArea = _actualCopperArea
        End Sub
        Public Sub setFeasability(ByVal _feasability As String)
            feasability = _feasability
        End Sub
        Public Sub setMaxiTurnsNumber(ByVal _maxiTurnsNumber As Double)
            maxiTurnsNumber = _maxiTurnsNumber
        End Sub
        Public Sub setCopperWeight(ByVal _copperWeight As Double)
            copperWeight = _copperWeight
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function
    End Class
    Public Class Magnet
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {}
        Private remanentFluxDensity As Double
        Private coercive_magnetic_field As Double
        Private BrThermalCoefficient As Double
        Private HcjThermalCoefficient As Double
        Private length As Double
        Private width As Double
        Private height As Double
        Sub New()
            tableName = "magnet"
        End Sub

        Public Sub setRemanentFluxDensity(ByVal value As Double)
            remanentFluxDensity = value
        End Sub

        Public Sub setCoerciveMagneticField(ByVal value As Double)
            coercive_magnetic_field = value
        End Sub

        Public Sub setBrThermalCoefficient(ByVal value As Double)
            BrThermalCoefficient = value
        End Sub

        Public Sub setHcjThermalCoefficient(ByVal value As Double)
            HcjThermalCoefficient = value
        End Sub

        Public Sub setLength(ByVal value As Double)
            length = value
        End Sub

        Public Sub setWidth(ByVal value As Double)
            width = value
        End Sub

        Public Sub setHeight(ByVal value As Double)
            height = value
        End Sub

        Public Function getRemanentFluxDensity() As Double
            Return remanentFluxDensity
        End Function

        Public Function getCoerciveMagneticField() As Double
            Return coercive_magnetic_field
        End Function

        Public Function getBrThermalCoefficient() As Double
            Return BrThermalCoefficient
        End Function

        Public Function getHcjThermalCoefficient() As Double
            Return HcjThermalCoefficient
        End Function

        Public Function getLength() As Double
            Return length
        End Function

        Public Function getWidth() As Double
            Return width
        End Function

        Public Function getHeight() As Double
            Return height
        End Function
    End Class
    Public Class RotorMagnet
        Private rotor As String
        Private magnet As String
        Private quantity As Integer
        Sub New(ByVal rotor As String, ByVal magnet As String)
            Me.rotor = rotor
            Me.magnet = magnet
            Me.quantity = quantity
        End Sub
        Public Function getRotorRef() As String
            Return rotor
        End Function
        Public Function getMagnetRef() As String
            Return magnet
        End Function
        Public Function getQuantity() As Integer
            Return quantity
        End Function
        Public Sub setRotor(ByVal rotor As String)
            Me.rotor = rotor
        End Sub
        Public Sub setManget(ByVal magnet As String)
            Me.magnet = magnet
        End Sub
        Public Sub setQuantity(ByVal quantity As Integer)
            Me.quantity = quantity
        End Sub
        Public Function getRotor() As Rotor
            Dim rotor As New Rotor
            rotor = rotor.getObjectByKey(Me.rotor, "Rotor", "rotor")
            Return rotor
        End Function
        Public Function getMagnet() As Magnet
            Dim magnet As New Magnet
            magnet = magnet.getObjectByKey(Me.magnet, "Magnet", "magnet")
            Return magnet
        End Function

        Sub update()
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "UPDATE rotor_magnet SET quantity = " & quantity & " WHERE rotor = '" & rotor & "' AND magnet = '" & magnet & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub

        Public Function insert() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "INSERT INTO rotor_magnet VALUES ('" & rotor & "', '" & magnet & "', " & quantity & ")"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
            Return True
        End Function

        Function delete() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "DELETE FROM rotor_magnet WHERE rotor = '" & rotor & "' AND magnet = '" & magnet & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
            Return True
        End Function

    End Class
    Public Class User
        Private login As String
        Private password As String
        Private firstName As String
        Private lastName As String
        Private email As String
        Private companyFunction As String
        Private userRight As Integer
        Private createdDate As Date
        Private expiredDays As Integer
        Sub New(ByVal _login As String)
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String
            Dim reader As SqlCeDataReader

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "SELECT * from [user] where login = '" & _login & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                reader = command.ExecuteReader()
                Try
                    While reader.Read()
                        setLogin(reader(0))
                        setPassword(reader(1))
                        setFirstName(reader(2))
                        setLastName(reader(3))
                        setEmail(reader(4))
                        setCompanyFunction(reader(5))
                        setUserRight(reader(6))
                        setCreatedDate(reader(7))
                        setExpiredDays(reader(8))
                    End While
                Catch ex As Exception
                Finally
                    reader.Close()
                End Try
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
        Public Sub setLogin(ByVal _login As String)
            login = _login
        End Sub
        Public Sub setPassword(ByVal _password As String)
            password = _password
        End Sub
        Public Sub setFirstName(ByVal _firstName As String)
            firstName = _firstName
        End Sub
        Public Sub setLastName(ByVal _lastName As String)
            lastName = _lastName
        End Sub
        Public Sub setEmail(ByVal _email As String)
            email = _email
        End Sub
        Public Sub setCompanyFunction(ByVal _functionCompany As String)
            companyFunction = _functionCompany
        End Sub
        Public Sub setUserRight(ByVal _userRight As String)
            userRight = _userRight
        End Sub
        Public Function getLogin() As String
            Return login
        End Function
        Public Function getPassword() As String
            Return password
        End Function
        Public Function getFirstName() As String
            Return firstName
        End Function
        Public Function getLastName() As String
            Return lastName
        End Function
        Public Function getEmail() As String
            Return email
        End Function
        Public Function getCompanyFunction() As String
            Return companyFunction
        End Function
        Public Function getUserRight() As String
            Return userRight
        End Function

        Function save() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "UPDATE [User] SET password = '" & password & "', first_name = '" _
            & firstName & "', last_name = '" & lastName & "', email = '" & email & "', company_function = '" & companyFunction & _
            "', user_right = '" & userRight & "', expired_days = " & expiredDays & " WHERE login = '" & login & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
            Return True
        End Function

        Public Function create() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "INSERT INTO [user](login, password, first_name, last_name, email, company_function, user_right, created_date, expired_days) VALUES ('" & login & "', '" & password & "', '" & firstName & "', '" & _
            lastName & "', '" & email & "', '" & companyFunction & "', '" & userRight & "', GETDATE(), " & expiredDays & ")"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
            Return True
        End Function

        Function delete() As Boolean
            Dim connectionString As String
            Dim connection As SqlCeConnection
            Dim command As SqlCeCommand
            Dim sql As String

            Dim source As String = My.Settings.Item("dataSource")
            connectionString = "Data Source=" & source & ";Persist Security Info=True;Password = RJOntp97@"
            sql = "DELETE FROM [User] WHERE login = '" & login & "'"
            connection = New SqlCeConnection(connectionString)
            Try
                connection.Open()
                command = New SqlCeCommand(sql, connection)
                Dim lines As Int16 = command.ExecuteNonQuery()
                command.Dispose()
                connection.Close()
            Catch ex As Exception
                MsgBox(ex.ToString)
                Return False
            End Try
            Return True
        End Function

        Function getExpiredDays() As Object
            Return expiredDays
        End Function

        Function getCreatedDate() As Date
            Return createdDate
        End Function

        Public Sub setCreatedDate(ByVal p1 As Date)
            createdDate = p1
        End Sub

        Public Sub setExpiredDays(ByVal p1 As Integer)
            expiredDays = p1
        End Sub

    End Class
    Public Class MaterialConductor
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private resistivity As Double
        Private thermalCoefficientAlpha As Double
        Private density As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "material_conductor"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function

        Public Sub setResistivity(ByVal value As Double)
            resistivity = value
        End Sub

        Public Sub setThermalCoefficientAlpha(ByVal value As Double)
            thermalCoefficientAlpha = value
        End Sub

        Public Sub setDensity(ByVal value As Double)
            density = value
        End Sub

        Public Function getResistivity() As Double
            Return resistivity
        End Function

        Public Function getThermalCoefficientAlpha() As Double
            Return thermalCoefficientAlpha
        End Function

        Public Function getDensity() As Double
            Return density
        End Function
    End Class

    Public Class MaterialMagnetic
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Private Bs As Double
        Private mu As Double
        Private Hc0 As Double
        Private mu0 As Double
        Private density As Double
        Private Khysteresis As Double
        Private Kfoucault As Double
        Private Kform As Double
        Public childrenList() As String = {}
        Sub New()
            tableName = "material_magnetic"
        End Sub
        Public Function getNewAdapVerion() As Integer
            countAdapVersion += 1
            Return countAdapVersion
        End Function

        Public Sub setBs(ByVal value As Double)
            Bs = value
        End Sub

        Public Sub setMu(ByVal value As Double)
            mu = value
        End Sub

        Public Sub setDensity(ByVal value As Double)
            density = value
        End Sub

        Public Sub setHc0(ByVal value As Double)
            Hc0 = value
        End Sub

        Public Sub setMu0(ByVal value As Double)
            mu0 = value
        End Sub

        Public Sub setKhysteresis(ByVal value As Double)
            Khysteresis = value
        End Sub

        Public Sub setKfoucault(ByVal value As Double)
            Kfoucault = value
        End Sub

        Public Sub setKform(ByVal value As Double)
            Kform = value
        End Sub

        Public Function getBs() As Double
            Return Bs
        End Function

        Public Function getMu() As Double
            Return mu
        End Function

        Public Function getDensity() As Double
            Return density
        End Function

        Public Function getHc0() As Double
            Return Hc0
        End Function

        Public Function getMu0() As Double
            Return mu0
        End Function

        Public Function getKhysteresis() As Double
            Return Khysteresis
        End Function

        Public Function getKfoucault() As Double
            Return Kfoucault
        End Function

        Public Function getKform() As Double
            Return Kform
        End Function
    End Class

    Public Class Calcul
        Private alternator As String
        Private ambientTemperature As Double
        Private Vdc As Double
        Private testConditions As Integer
        Private ICP As Double
        Private environment As Integer
        Private preHeatingSpeed As Double
        Private speed(0 To 10) As Double

        Sub New(ByVal alternator As String,
                ByVal testConditions As Integer,
                ByVal environment As Integer)

            Dim alter As New Component
            If alter.exist("alternator", alternator) Then
                With Me
                    .alternator = alternator
                    .testConditions = testConditions
                    .environment = environment
                End With
            Else
                MsgBox("Alternator doesn't exit in data base")
            End If
        End Sub

        Public Sub setAmbientTemperature(ByVal value As Double)
            ambientTemperature = value
        End Sub

        Public Sub setVdc(ByVal value As Double)
            Vdc = value
        End Sub

        Public Sub setTestConditions(ByVal value As Integer)
            testConditions = value
        End Sub

        Public Sub setICP(ByVal value As Double)
            ICP = value
        End Sub

        Public Sub setEnvironment(ByVal value As Integer)
            environment = value
        End Sub

        Public Sub setPreHeatingSpeed(ByVal value As Double)
            preHeatingSpeed = value
        End Sub

        Public Sub setSpeed(ByVal speed() As Double)
            Me.speed = speed
        End Sub

        Public Function getAlternator() As String
            Return alternator
        End Function

        Public Function getAmbientTemperature() As Double
            Return ambientTemperature
        End Function

        Public Function getVdc() As Double
            Return Vdc
        End Function

        Public Function getTestConditions() As Integer
            Return testConditions
        End Function

        Public Function getICP() As Double
            Return ICP
        End Function

        Public Function getEnvironment() As Double
            Return environment
        End Function

        Public Function getPreHeatSpeed() As Double
            Return preHeatingSpeed
        End Function

        Sub writeGeneralInfo(ByRef excelWorkSheet As Worksheet)
            excelWorkSheet.Range("C9").Value = Me.ambientTemperature
            excelWorkSheet.Range("C10").Value = Me.Vdc
            excelWorkSheet.Range("G8").Value = Me.ICP
            excelWorkSheet.Range("G9").Value = Me.testConditions
            excelWorkSheet.Range("G10").Value = Me.environment
            excelWorkSheet.Range("G11").Value = Me.preHeatingSpeed
        End Sub

        Sub writeSpeeds(ByRef excelWorkSheet As Worksheet)
            Dim index As Integer = 19
            For i As Integer = 1 To speed.Length Step 1
                Try
                    excelWorkSheet.Range("B" & index).Value = speed(i - 1)
                    index += 1
                Catch e As Exception
                End Try
            Next
        End Sub

        Sub writeAlter(ByRef workSheet As Worksheet)

            Dim alter As New Alternator
            alter = alter.getObjectByKey(Me.alternator, "Alternator", "alternator")

            workSheet.Range("D4").Value = alter.getRef()
            workSheet.Range("D5").Value = alter.getVoltage()
            workSheet.Range("D6").Value = alter.getNominalOutput()
            workSheet.Range("D7").Value = alter.getElectricalDefinition
            workSheet.Range("D8").Value = alter.getPolePairsNumber
            

            Dim statorAssembly As New StatorAssembly
            statorAssembly = statorAssembly.getObjectByKey(alter.getStatorAssembly(), "StatorAssembly", "stator_assembly")
            Dim windingStator As New WindingStator
            windingStator = windingStator.getObjectByKey(statorAssembly.getWindingStator(), "WindingStator", "winding_stator")
            Dim statorStack As New StatorStack
            statorStack = statorStack.getObjectByKey(windingStator.getStatorStack(), "StatorStack", "stator_stack")


            With statorStack
                workSheet.Range("D35").Value = .getMaterialMagnetic
                workSheet.Range("D36").Value = .getOuterDiameter
                workSheet.Range("D37").Value = .getStackLength
                workSheet.Range("D38").Value = .getLaminationSheetThickness
                workSheet.Range("D39").Value = .getInnerDiameter
            End With

           


            With statorStack
                workSheet.Range("D42").Value = .getSlotNumber
                workSheet.Range("D43").Value = .getTeethWidth
                workSheet.Range("D44").Value = .getSlotHeight
                workSheet.Range("D45").Value = .getSlotOpening
                workSheet.Range("D46").Value = .getBottomSlotCornerRadius

                workSheet.Range("D47").Value = .getTeethShoeHeight
                workSheet.Range("D48").Value = .getSlotOpeningHeight
            End With


            With statorAssembly
                workSheet.Range("D51").Value = .getMaterialConductor
                Dim material As New MaterialConductor
                material = material.getObjectByKey(.getMaterialConductor, "MaterialConductor", "material_conductor")
                workSheet.Range("D52").Value = material.getResistivity
                workSheet.Range("D53").Value = material.getThermalCoefficientAlpha
                workSheet.Range("D54").Value = material.getDensity
                workSheet.Range("D55").Value = .getPhaseNumber
                workSheet.Range("D56").Value = .getTurnsNumberPerPhase
                workSheet.Range("D57").Value = .getParallelWiresNumber
                workSheet.Range("D58").Value = .getWireDiameter
                workSheet.Range("D59").Value = .getConnectionType
                'workSheet.Range("D61").Value = .getPhaseResistanceAt20

                workSheet.Range("J47").Value = .getEndWindingHeight
            End With

            Dim rotor As New Rotor
            rotor = rotor.getObjectByKey(alter.getRotor, "Rotor", "rotor")
            workSheet.Range("D70").Value = rotor.getMountingType

            Dim clawPole As New ClawPoles
            clawPole = clawPole.getObjectByKey(rotor.getClawPoles(), "ClawPoles", "claw_poles")
            With clawPole
                workSheet.Range("D73").Value = .getMaterialMagnetic
                workSheet.Range("D74").Value = .getThermalTreatment
                workSheet.Range("D75").Value = .getOuterDiameter
                workSheet.Range("D76").Value = .getPoleEndDiscThickness
                workSheet.Range("D77").Value = .getInnerRadiusAtClawBandPart
                workSheet.Range("D78").Value = .getClawLengthAtSlopeChange
                workSheet.Range("D79").Value = .getInnerRadiusAtSlopeChange
                workSheet.Range("D80").Value = .getTotalClawLength
                workSheet.Range("D81").Value = .getInnerDiameterAtTip
                workSheet.Range("D82").Value = .getContactThickness
                workSheet.Range("D83").Value = .getPoleEndDiscDiameter
                workSheet.Range("D85").Value = .getClawLengthAtACut
                workSheet.Range("D86").Value = .getClawWidthAtACut
                workSheet.Range("D87").Value = .getMachinedHalfWidthAtACut
                workSheet.Range("D88").Value = .getClawLengthAtBCut
                workSheet.Range("D89").Value = .getClawWidthAtBcut
                workSheet.Range("D90").Value = .getMachinedHalfWidthAtBCut
                workSheet.Range("D91").Value = .getClawWidthAtRoot
                workSheet.Range("D92").Value = .getMaxiClawLength
                workSheet.Range("D93").Value = .getClawLateralAngle
                workSheet.Range("D94").Value = .getChamferType
                workSheet.Range("D95").Value = .getChamferAngle
            End With

            With rotor
                workSheet.Range("J79").Value = .getMaterialMagnetic
                workSheet.Range("J80").Value = .getThermalTreatment
                workSheet.Range("J81").Value = .getOuterDiameter
                workSheet.Range("J82").Value = .getCoreLength
                workSheet.Range("J83").Value = .getCenteringLengthOfClawPole
                workSheet.Range("J84").Value = .getCenteringDiameterOfClawPole
                workSheet.Range("J85").Value = .getShaftDiameter
            End With

            Dim fieldCoil As New FieldCoil
            fieldCoil = fieldCoil.getObjectByKey(rotor.getFieldCoil, "FieldCoil", "field_coil")
            With fieldCoil
                workSheet.Range("J88").Value = .getMaterialConductor
                Dim material As New MaterialConductor
                material = material.getObjectByKey(.getMaterialConductor, "MaterialConductor", "material_conductor")
                workSheet.Range("J89").Value = material.getResistivity
                workSheet.Range("J90").Value = material.getThermalCoefficientAlpha
                workSheet.Range("J91").Value = material.getDensity
                workSheet.Range("J92").Value = .getTurnsNumber
                workSheet.Range("J93").Value = .getWireDiameter
                workSheet.Range("J94").Value = .getResistanceAt20
                workSheet.Range("J95").Value = .getFilGrad1IndiceDeTemps
            End With
        End Sub

        Sub writeMaterial(ByRef material As Worksheet)
            Dim alter As New Alternator
            alter = alter.getObjectByKey(Me.alternator, "Alternator", "alternator")
            Dim statorAssembly As New StatorAssembly
            statorAssembly = statorAssembly.getObjectByKey(alter.getStatorAssembly(), "StatorAssembly", "stator_assembly")
            Dim windingStator As New WindingStator
            windingStator = windingStator.getObjectByKey(statorAssembly.getWindingStator(), "WindingStator", "winding_stator")
            Dim statorStack As New StatorStack
            statorStack = statorStack.getObjectByKey(windingStator.getStatorStack(), "StatorStack", "stator_stack")
            Dim materialStator As New MaterialMagnetic
            materialStator = materialStator.getObjectByKey(statorStack.getMaterialMagnetic(), "MaterialMagnetic", "material_magnetic")
            With materialStator
                material.Range("G37").Value = .getBs()
                material.Range("G38").Value = .getMu()
                material.Range("G39").Value = .getHc0()
                material.Range("G40").Value = .getMu0()
            End With

            Dim rotor As New Rotor
            rotor = rotor.getObjectByKey(alter.getRotor(), "Rotor", "rotor")
            Dim materialRotor1 As New MaterialMagnetic
            materialRotor1 = materialRotor1.getObjectByKey(rotor.getMaterialMagnetic(), "MaterialMagnetic", "material_magnetic")
            With materialRotor1
                material.Range("H37").Value = .getBs()
                material.Range("H38").Value = .getMu()
                material.Range("H39").Value = .getHc0()
                material.Range("H40").Value = .getMu0()
            End With

            Dim clawPoles As New ClawPoles
            clawPoles = clawPoles.getObjectByKey(rotor.getClawPoles(), "ClawPoles", "claw_poles")
            Dim materialRotor2 As New MaterialMagnetic
            materialRotor2 = materialRotor2.getObjectByKey(clawPoles.getMaterialMagnetic(), "MaterialMagnetic", "material_magnetic")
            With materialRotor2
                material.Range("I37").Value = .getBs()
                material.Range("I38").Value = .getMu()
                material.Range("I39").Value = .getHc0()
                material.Range("I40").Value = .getMu0()
            End With
        End Sub

        Sub writeThermal(ByVal thermal As Worksheet)
            Dim alter As New Alternator
            alter = alter.getObjectByKey(Me.alternator, "Alternator", "alternator")
            Dim statorAssembly As New StatorAssembly
            statorAssembly = statorAssembly.getObjectByKey(alter.getStatorAssembly(), "StatorAssembly", "stator_assembly")
            Dim th As New ThermalCoefficient
            th = th.getObjectByKey(statorAssembly.getThermalCoefficient(), "ThermalCoefficient", "thermal_coefficient")
            With th
                thermal.Range("T40").Value = .getATh
                thermal.Range("T41").Value = .getAlpha
                thermal.Range("T42").Value = .getKTh
                thermal.Range("T43").Value = .getTambRef
                thermal.Range("T44").Value = .getGNat
            End With

            Dim rotor As New Rotor
            rotor = rotor.getObjectByKey(alter.getRotor(), "Rotor", "rotor")
            th = th.getObjectByKey(rotor.getThermalCoefficient(), "ThermalCoefficient", "thermal_coefficient")
            With th
                thermal.Range("U40").Value = .getATh
                thermal.Range("U41").Value = .getAlpha
                thermal.Range("U42").Value = .getKTh
                thermal.Range("U43").Value = .getTambRef
                thermal.Range("U44").Value = .getGNat
            End With
        End Sub

    End Class

    Public Class StatorAssembly
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {"winding_stator", "material_conductor", "thermal_coefficient"}
        Private phaseNumber As Integer
        Private turnsNumberPerPhase As Integer
        Private parallelWiresNumber As Integer
        Private turnNumber As Integer
        Private connectionType As Integer
        Private windingType As Integer
        Private wireType As Integer
        Private wireDiameter As Double
        Private wireHeight As Double
        Private wireWidth As Double
        Private thermalGrade As Double
        Private thermalCoefficient As String
        Private slotWedgeThickness As Double
        Private materialConductor As String
        Private windingStator As String
        Private endWindingHeight As Double
        Sub New()
            tableName = "stator_assembly"
        End Sub

        Public Sub setPhaseNumber(ByVal value As Integer)
            phaseNumber = value
        End Sub

        Public Sub setParallelWiresNumber(ByVal value As Integer)
            parallelWiresNumber = value
        End Sub

        Public Sub setTurnNumber(ByVal value As Integer)
            turnNumber = value
        End Sub

        Public Sub setWireType(ByVal value As Integer)
            wireType = value
        End Sub

        Public Sub setWireDiameter(ByVal value As Double)
            wireDiameter = value
        End Sub

        Public Sub setWireHeight(ByVal value As Double)
            wireHeight = value
        End Sub

        Public Sub setWireWidth(ByVal value As Double)
            wireWidth = value
        End Sub

        Public Sub setThermalGrade(ByVal value As Double)
            thermalGrade = value
        End Sub

        Public Sub setSlotWedgeThickness(ByVal value As Double)
            slotWedgeThickness = value
        End Sub

        Public Sub setMaterialConductor(ByVal value As String)
            materialConductor = value
        End Sub

        Public Sub setWindingStator(ByVal value As String)
            windingStator = value
        End Sub

        Public Function getPhaseNumber() As Integer
            Return phaseNumber
        End Function

        Public Function getParallelWiresNumber() As Integer
            Return parallelWiresNumber
        End Function

        Public Function getTurnNumber() As Integer
            Return turnNumber
        End Function

        Public Function getWireType() As Integer
            Return wireType
        End Function

        Public Function getWireDiameter() As Double
            Return wireDiameter
        End Function

        Public Function getWireHeight() As Double
            Return wireHeight
        End Function

        Public Function getWireWidth() As Double
            Return wireWidth
        End Function

        Public Function getThermalGrade() As Double
            Return thermalGrade
        End Function

        Public Function getSlotWedgeThickness() As Double
            Return slotWedgeThickness
        End Function

        Public Function getMaterialConductor() As String
            Return materialConductor
        End Function

        Public Function getWindingStator() As String
            Return windingStator
        End Function
        Public Sub setConnectionType(ByVal value As Integer)
            connectionType = value
        End Sub
        Public Sub setWindingType(ByVal value As Integer)
            windingType = value
        End Sub
        Public Sub setTurnsNumberPerPhase(ByVal value As Integer)
            turnsNumberPerPhase = value
        End Sub
        Public Function getConnectionType() As Integer
            Return connectionType
        End Function
        Public Function getWindingType() As Integer
            Return windingType
        End Function
        Public Function getTurnsNumberPerPhase() As Integer
            Return turnsNumberPerPhase
        End Function
        Public Sub setThermalCoefficient(ByVal value As String)
            thermalCoefficient = value
        End Sub
        Public Function getThermalCoefficient() As String
            Return thermalCoefficient
        End Function
        Public Sub setEndWindingHeight(ByVal value As Double)
            endWindingHeight = value
        End Sub
        Public Function getEndWindingHeight() As Double
            Return endWindingHeight
        End Function
    End Class

    Public Class WindingStator
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {"stator_stack"}
        Private statorStack As String
        Public Sub setStatorStack(ByVal value As String)
            statorStack = value
        End Sub

        Public Function getStatorStack() As String
            Return statorStack
        End Function

        Sub New()
            tableName = "winding_stator"
        End Sub
    End Class

    Public Class StatorStack
        Inherits Component
        Public Shared countAdapVersion As Integer = 0
        Public childrenList() As String = {"material_magnetic"}
        Private outerDiameter As Double
        Private stackLength As Double
        Private laminationSheetThickness As Double
        Private materialMagnetic As String
        Private slotNumber As Double
        Private slotHeight As Double
        Private slotOpening As Double
        Private bottomSlotCornerRadius As Double
        Private teethShoeHeight As Double
        Private slotWithParallelSides As Integer
        Private slotWidth As Double
        Private teethWidth As Double
        Private slotOpeningHeight As Double
        Private innerDiameter As Double
        Private tipAngle As Double
        Private slotBottomDiameter As Double
        Sub New()
            tableName = "stator_stack"
        End Sub

        Public Sub setOuterDiameter(ByVal value As Double)
            outerDiameter = value
        End Sub

        Public Sub setStackLength(ByVal value As Double)
            stackLength = value
        End Sub

        Public Sub setLaminationSheetThickness(ByVal value As Double)
            laminationSheetThickness = value
        End Sub

        Public Sub setMaterialMagnetic(ByVal value As String)
            materialMagnetic = value
        End Sub

        Public Sub setSlotNumber(ByVal value As Double)
            slotNumber = value
        End Sub

        Public Sub setSlotHeight(ByVal value As Double)
            slotHeight = value
        End Sub

        Public Sub setSlotOpening(ByVal value As Double)
            slotOpening = value
        End Sub

        Public Sub setBottomSlotCornerRadius(ByVal value As Double)
            bottomSlotCornerRadius = value
        End Sub

        Public Sub setTeethShoeHeight(ByVal value As Double)
            teethShoeHeight = value
        End Sub

        Public Sub setSlotWithParallelSides(ByVal value As Integer)
            slotWithParallelSides = value
        End Sub

        Public Sub setSlotWidth(ByVal value As Double)
            slotWidth = value
        End Sub

        Public Sub setTeethWidth(ByVal value As Double)
            teethWidth = value
        End Sub

        Public Sub setSlotOpeningHeight(ByVal value As Double)
            slotOpeningHeight = value
        End Sub

        Public Sub setInnerDiameter(ByVal value As Double)
            innerDiameter = value
        End Sub

        Public Function getOuterDiameter() As Double
            Return outerDiameter
        End Function

        Public Function getStackLength() As Double
            Return stackLength
        End Function

        Public Function getLaminationSheetThickness() As Double
            Return laminationSheetThickness
        End Function

        Public Function getMaterialMagnetic() As String
            Return materialMagnetic
        End Function

        Public Function getSlotNumber() As Double
            Return slotNumber
        End Function

        Public Function getSlotHeight() As Double
            Return slotHeight
        End Function

        Public Function getSlotOpening() As Double
            Return slotOpening
        End Function

        Public Function getBottomSlotCornerRadius() As Double
            Return bottomSlotCornerRadius
        End Function

        Public Function getTeethShoeHeight() As Double
            Return teethShoeHeight
        End Function

        Public Function getSlotWithParallelSides() As Integer
            Return slotWithParallelSides
        End Function

        Public Function getSlotWidth() As Double
            Return slotWidth
        End Function

        Public Function getTeethWidth() As Double
            Return teethWidth
        End Function

        Public Function getSlotOpeningHeight() As Double
            Return slotOpeningHeight
        End Function

        Public Function getInnerDiameter() As Double
            Return innerDiameter
        End Function

        Public Sub setTipAngle(ByVal value As Double)
            tipAngle = value
        End Sub

        Public Function getTipAngle() As Double
            Return tipAngle
        End Function

        Public Sub setSlotBottomDiameter(ByVal value As Double)
            slotBottomDiameter = value
        End Sub

        Public Function getSlotBottomDiameter() As Double
            Return slotBottomDiameter
        End Function
    End Class
End Namespace

